import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './plugins/app.js'
import './assets/css/global.css'
import axios from 'axios'
Vue.prototype.$http = axios;
Vue.config.productionTip = false;
const isDebug = true;

if (isDebug) {
  axios.defaults.baseURL =
    "http://localhost:8080/";
} else {
  axios.defaults.baseURL = "interface/";
}
axios.defaults.withCredentials = true; // 允许携带cookie
axios.interceptors.request.use(config => {
  return config;
});
// 拦截响应response，并做一些错误处理

//response拦截器
axios.interceptors.response.use(
  (response) => {
    const data = response.data;
    // store.commit("hideLoading");
    return response;
  },
  (err) => {
    // store.commit("hideLoading");
    let res = "加载失败，请检查你的网络！";
    if (err && err.response) {
      let resMap = {
        400: "请求错误",
        401: "未授权，请登录",
        403: "拒绝访问",
        404: `请求地址出错: ${err.response.config.url}`,
        408: "请求超时",
        500: "服务器内部错误",
        501: "服务未实现",
        502: "网关错误",
        503: "服务不可用",
        504: "网关超时",
        505: "HTTP版本不受支持",
      };
      if (resMap[err.response.status]) {
        res = resMap[err.response.status];
      }
    }
    console.log(res)
    // Notify({ type: "danger", message: res });
  }
);

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')


  